<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/fragment::top">

</head>

<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">
    <!--左侧导航-->
    <div th:replace="common/fragment::leftmenu"></div>
    <!--End 左侧导航-->

    <!--头部信息-->
    <div th:replace="common/fragment::header"></div>
    <!--End 头部信息-->

    <!--页面主要内容-->
    <main class="lyear-layout-content">
      <div class="container-fluid">
      </div>
      <!--采购单详情-->

      <!-- 采购入库单表格 循环-->

      <!--添加明细-->
      <div id="detail-table">
        <table class="table table-bordered">
          <thead id="goodheader">
          <tr>
            <th hidden="hidden">入库单id</th>
            <th>序号</th>
            <th>采购订单</th>
            <th>供应商</th>
            <th>要货日期</th>
            <th>入库单</th>
            <th>编制日期</th>
            <th>责任人</th>
            <th>状态</th>
            <th>操作</th>
          </tr>
          </thead>
          <tbody>
          <tr th:each="sellout:${sellOutlist}">
            <td hidden="hidden" th:text="${sellout.id ne null?sellout.id:''}">入库单id
            </th>
            <td th:text="${selloutStat.index}">序号
            </th>
            <td th:text="${sellout.sellPO.name}">采购订单</td>
            <td th:text="${sellout.sellPO.custPO.name}">供应商</td>
            <td th:text="${#dates.format(sellout.sellPO.need, 'yyyy-MM-dd')}">要货日期</td>
            <td th:text="${sellout.name}">入库单</td>
            <td th:text="${#dates.format(sellout.createTime, 'yyyy-MM-dd')}">编制日期</td>
            <td th:text="${sellout.userPO.username}">责任人</td>
            <td th:text="${selloutstatus[sellout.status]}">状态</td>
            <td>
              <div class="btn-group">
                <a class="btn btn-xs btn-default auditsellout-btn" data-toggle="tooltip"

                   th:href="${sellout.id}" title="审核">
                  <i class="mdi mdi-pencil"></i>
                </a>
              </div>
            </td>
          </tr>

          </tbody>
        </table>
      </div>
      <!--END添加明细-->
    </main>
    <!--End 页面主要内容-->
  </div>
</div>

<div th:insert="common/fragment::tail-script"></div>

<style>
  .modify {
    color: #ac2925;
    font-weight: bolder;
  }

  .hiddendetail {
    display: none;
  }

  .changedetail {
    color: #7A56D4;
    font-weight: bolder;
  }
</style>

<script type="text/javascript">
  $(function () {
    let flag = true

// 选择-->采购订单内容切换
    $('#sellchoice').change(function () {
      let tablabel = ''
      let val = $('#sellchoice  option:selected').text()
      if (val.indexOf('请选择') == 0) {
        tablabel = 'tab' + "-999"
      } else {
        tablabel = "tab" + val
      }

      $('.loopsell').attr('hidden', 'hidden')
      $('#' + tablabel).attr('hidden', false)
    });
// 选择-->采购订单内容切换

// 打开审计明细
    $('.auditsellout-btn').each(function (i,e) {
  $(e).click(function (e) {
    let sellid = $(this).attr('href');
    window.location.href = '/sellout/auditeditsellout.do?id=' + sellid
    e.preventDefault()

    return false
  })
    })


// END明细

// 输入数量 为整数
    $('.incount').each(function (i, e) {
      $(e).blur(function () {
        let val = parseInt($(e).val())

        if (val == null || val == "Null" || val == '' || isNaN(val)) {
          $(this).val(null)
          return
        }
        if (val === 'NaN') {
          $(this).val(null)
          return
        }

        if (parseInt(val) < 0) {
          confirmMsg("输入单价有误")
          return false;
        }

        if (parseInt(val) > 0) {
          $(e).addClass('changedetail')
        }
        $(this).val(val)

      });
    });

// 保存订单
    /*PurInPO{
        createTime	string($date-time)
        id	integer($int64)
        name	string
        need	string($date-time)
        sellOutDetailPOList	[...]
        sellPO	PurPO{...}
        updateTime	string($date-time)
        userPO	UserPO{...}
    }*/
    // $('#save-detail-btn').click(function () {
    //   let sellid = $('#sellchoice').val()
    //   let sellPO = {id: sellid}
    //   // 停机明细
    //   let detailtable = ''
    //   let val = $('#sellchoice  option:selected').text()
    //   if (val.indexOf('请选择') == 0) {
    //     detailtable = 'detailtable' + "-999"
    //   } else {
    //     detailtable = "detailtable" + val
    //   }
    //
    //   // 循环有变化的数值
    //   let sellOutDetailPOList = []
    //   $('#' + detailtable).children('tr').each(function (i, e) {
    //     // console.log($(e).children('.goodid').text())
    //     let val = $(e).find('.incount').val()
    //
    //     if (val > 0) {
    //       let val = parseInt($(e).find('.incount').val())
    //       let goodid = $(e).children('.goodid').text()
    //
    //       let goodPO = {id: goodid}
    //       let PurInDetailPO = {
    //         goodPO: goodPO,
    //         goodcount: val
    //       }
    //       sellOutDetailPOList.push(PurInDetailPO)
    //     }
    //   });
    //   // 生成json
    //   let data = {
    //     sellPO: sellPO,
    //     sellOutDetailPOList: sellOutDetailPOList
    //   }
    //   // 发送ajax
    //   post_ajax("/sellout/savesellout.ajax", data, "/sellout/selloutstock.do")
    // });

  });
</script>
</body>
</html>